{% extends 'window.twig' %}
{% block body %}
    <div class="admin-main-container">
        <div class="data-view">
        <div class="clearfix btn-control">
            <div class="col-xs-8" style="padding-left:0;">
                <span class="action-btn">
                    <a class="btn btn-default" href="user.view.add">新 增</a>
                    <a class="btn btn-default ajax-post" href="user.status.enabled" target-form="ids">启 用</a>
                    <a class="btn btn-default ajax-post" href="user.status.disabled" target-form="ids">禁 用</a>
                    <a class="btn btn-default ajax-post confirm" href="user.status/delete" target-form="ids">删 除</a>
                </span>
                &nbsp; &nbsp; &nbsp; &nbsp;
                <a class="btn btn-primary set-user-group">设置用户分组</a>
            </div>

            <!-- 高级搜索 -->
            <div class="search-form  col-xs-4 text-right">
                <form action="user.list">
                    <div class="input-group">
                        <input type="text" name="nickname" class="search-input form-control" value="{{ kw }}"
                               placeholder="请输入用户昵称或者登录名">
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="submit" id="search">
                                <i class="glyphicon glyphicon-search"></i>
                            </button>
                        </span>
                    </div>
                </form>
            </div>
        </div>
        <!-- 数据列表 -->
        <div class="data-table with-padding">
            <table class="table table-bordered table-striped ">
                <thead>
                <tr>
                    <th class="row-selected row-selected"><input class="check-all" data-target=".ids" type="checkbox"></th>
                    <th class="">UID</th>
                    <th class="">昵称</th>
                    <th class="">登录名</th>
                    <th class="">用户组</th>
                    <th class="">登录次数</th>
                    <th class="">最后登录时间</th>
                    <th class="" style="width: 130px">最后登录IP</th>
                    <th class="">状态</th>
                    <th class="">操作</th>
                </tr>
                </thead>
                <tbody>
                {% for user in user_list %}
                <tr>
                    <td><input {{ user.is_sys?'disabled="disabled"':'class="ids"' }} type="checkbox" name="id[]" value="{{ user.uid }}"></td>
                    <td>{{ user.uid }}</td>
                    <td>{{ user.nick_name }}</td>
                    <td>{{ user.login_name }}</td>
                    <td>{{ user.title }}</td>
                    <td>{{ user.login_count }}</td>
                    <td><span>{{ user.last_login_time ? user.last_login_time|date("Y-m-d H:i"):'从未登录' }}</span></td>
                    <td><a href="http://ip138.com/ips138.asp?ip={{ user.last_login_ip }}" target="_blank">
                            {{ user.last_login_ip }}</a></td>
                    <td>{{ DataState(user.state) }}</td>

                    <td>
                    {% if user.is_sys == 0 %}
                        <a href="user.view.edit?uid={{ user.uid }}">编辑信息</a>
                    {% endif %}
                    </td>

                </tr>
                {% endfor  %}
                </tbody>
            </table>
            <div style="height: 50px;"></div>
        </div>
        </div>
        <!-- 数据信息及分页 -->
        {% include 'block/page.twig' %}
    </div>
{% endblock %}
{% block script %}
    <script type="text/javascript">
        $(function(){
            util.resize(window,800);
            $('.set-user-group').on('click',function(){
                var ids = $('.ids:checked').map(function(){
                    return this.value;
                }).get();
                if(ids.length == 0){
                    dx.msg('请选择要分组的用户',{time:1500});
                    return false;
                }
                var opts = {
                    type: 2,
                    fix: false, //不固定
                    area: ['300px', '120px'],
                    topIndex:9999,
                    maxmin: false,
                    shade:[0.8, '#393D49'],
                    content: 'user.group.select?id=' + ids.join(','),
                    title:'选择用户组',
//                    skin: 'demo-class',
                    end:function(tag){
                        if(tag && tag == 'success'){
                            location.reload();
                            return false;
                        }
                        layer.iframeAuto(index);
                    }
                }
                index = layer.open(opts);return false;
            });
        });
    </script>
{% endblock %}